package com.mzj.saas.mservice.house.repository;

import com.mzj.saas.mservice.lock.entity.LockFrozen;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

public interface LockFrozenRepository extends PagingAndSortingRepository<LockFrozen, Long>, JpaSpecificationExecutor<LockFrozen> {

    LockFrozen findByLockAuditId(Long lockAuditId);

    @Query(value = "SELECT * FROM saas_house_lock_frozen WHERE lock_audit_id = ?1 AND operation_time = ?2", nativeQuery = true)
    LockFrozen findByLockAuditIdAndOperationTime(Long lockAuditId, String operationTime);

    @Query(value = "select * from  saas_house_lock_frozen where lock_id=?1 and type =?2 GROUP BY operation_time DESC LIMIT 1", nativeQuery = true)
    LockFrozen findByLockIdAndType(Long lockId, Integer type);


    @Query(value = "select * from  saas_house_lock_frozen where lock_id=?1  and lock_audit_id = ?2 and type =?3 GROUP BY operation_time DESC LIMIT 1", nativeQuery = true)
    LockFrozen findByLockIdAndLockAuditIdAndType(Long lockId, Long lockAuditId,Integer type);

}
